import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;

public class demo1 {
    public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException {
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder=documentBuilderFactory.newDocumentBuilder();
        Document doc=documentBuilder.parse("src/demo1.xml");
        NodeList barndList=doc.getElementsByTagName("Brand");
        for (int i = 0; i < barndList.getLength(); i++) {
            Node brand= barndList.item(i);
            Element element=(Element) brand;
            String attrValue=element.getAttribute("name");
            NodeList types=element.getChildNodes();
            for (int j = 0; j < types.getLength(); j++) {
                Element typeElement=((Element) types.item(j));
                String type=typeElement.getAttribute("name");
                System.out.println("手机"+attrValue);
            }
        }
    }
}
